package com.yao.smy.service;

import com.yao.smy.domain.Visitor;
import com.yao.smy.repository.VisitorRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class VisitorServiceImpl implements VisitorService {

    @Autowired
    private VisitorRepository visitorRepository;

    @Override
    public void addVisitor(Visitor visitor) {
        visitorRepository.save(visitor);
    }

    @Override
    public void deleteVisitor(String visitorId) {
        visitorRepository.deleteById(visitorId);
    }

    @Override
    public void updateVisitor(Visitor visitor) {
        visitorRepository.save(visitor);
    }

    @Override
    public Visitor getVisitor(String visitorId) {
        return visitorRepository.findById(visitorId).orElse(null);
    }

    @Override
    public List<Visitor> getAllVisitors() {
        return visitorRepository.findAll();
    }
}